package com.jambo.yudada.config;

import io.reactivex.Scheduler;
import io.reactivex.schedulers.Schedulers;
import lombok.Data;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

@Configuration
@Data
//为vip建立线程池
public class VipSchedulerConfig {
    @Bean
    public Scheduler vipScheduler() {
    ThreadFactory threadFactory=new ThreadFactory() {
        private final AtomicInteger poolNumber = new AtomicInteger(1);
        @Override
        public Thread newThread(@NotNull Runnable r) {
Thread t=new Thread(r,"VIPThreadPool-"+poolNumber.getAndIncrement());
            return t;
        }
    };
        ExecutorService executorService = Executors.newScheduledThreadPool(10,threadFactory);
    return Schedulers.from(executorService);
    }
}
